{*SMARTY*}
{extends file='common_layout.tpl'}
{block name=styles append}
   <style>
      body.mode_query .page {
         width:auto;
         margin-left:20px;
         margin-right:auto;
      }
      .main form.query {
         width:88%;
         padding:0px;
         border-color:#00709B;
      }
      .main form.query, div.result.table {
         width:88%;
         margin:0 auto;
      }
      *[itemprop="breadcrumb"] {
         display:block;
         padding:0 0 10px;
         margin:0 0 10px;
         font-size:8px;
         background:000;
      }
      *[itemprop="breadcrumb"] ul {
         padding:0;
         margin:0;
      }
      *[itemprop="breadcrumb"] ul li a {
         color:#a67600;
      }
      *[itemprop="breadcrumb"] ul li {
         display:inline-block;
         padding:0;
         margin:0;
         border-style:none;
      }
      *[itemprop="breadcrumb"] ul li:before {
         content:" > ";
         color:#a67600;
      }
      *[itemprop="breadcrumb"] ul li:first-child:before {
         content: "";
      }
      *[itemprop="breadcrumb"] ul li:last-child a {

      }
      .main form h2 {
         background-color: #00709B;
         border-radius: 10px 10px 0 0;
         color: #FFFFFF;
         margin: 0 0 10px;
         padding: 5px 0;
      }
      .main table caption {
         background-color: #00709B;
         color:#fff;
         border-radius:10px 10px 0 0;
      }
      .main table {
         width:100%;
         max-width:100%;
         border:2px solid #00709B;
      }
      .main table thead tr th {
         background:#FFC840;
         color:#000;
      }
      .main table tr td {
         border-bottom-style:none;
         background:#e0e0e0;
      }
      .main table tr td:nth-child(odd) {
         background:#e8e8e8;
      }
      .main table tr:nth-child(odd) td {
         background:#d0d0d0;
      }
      .main table tr:nth-child(odd) td:nth-child(odd) {
         background:#d8d8d8;
      }
      .main table thead tr:last-child td {
         border-bottom-style:none;
      }
   </style>
{/block}
{block name=nav}
<ul>
   <li><a href="{add::config()->base_url}">Home</a></li>
   <li style="text-align:right"><a href="{add::config()->base_url}login?mode=logout">Logout</a></li>
</ul>
{/block}
{block name=post_body_scripts append}
   <script type="text/javascript">
      $ajax_forms = $('form[data-ajax-target]');

      $ajax_forms.submit(
            function () {
               var $this = $(this);
               var ajax_settings = {};

               if ($this.attr('method'))
                  ajax_settings.type = $this.attr('method');


               ajax_settings.data = $this.serialize();

               if (ajax_settings.type.toLowerCase()  == "get") {
                  if (window.history.pushState)
                     window.history.pushState({},null, '?' + ajax_settings.data);
               }
               ajax_settings.data += '&ajax=1';

               if ($this.attr('data-ajax-target')) {
                  var $target = $($this.attr('data-ajax-target'));
                  $target.html('<div class="loading">Loading...</div>');
               }


               ajax_settings.complete = function (response) {
                     process_json(response.responseText,$target)
                  };
               $.ajax(
                     $this.attr('action') ? $this.attr('action') : '',
                     ajax_settings
                  );

               return false;
            }
         );

      $ajax_links = $('a[data-ajax-target]');

      $ajax_links.click(
            function () {
               var $this = $(this);
               var $target;

               if ($this.attr('data-ajax-target')) {
                  var $target = $($this.attr('data-ajax-target'));
                  $target.html('<div class="loading">Loading...</div>');
               }

               $.get($this.attr('href'),{ ajax:1 },function(data) { process_json(data,$target); });
               return false;
            }
         );


      function process_json(json_string,target) {
         var json = $.parseJSON(json_string);
         var $target = $(target);
         switch (json.type) {
            case 'eval':
               eval(json.script);
            break;
            default:
               if (json.message) {
                  if ($target) {
                     $target.html('<div>'+json.message+'</div>');
                  }
                  else {
                     alert(json.message);
                  }
               }
               else if (json.error_message) {
                  if ($target) {
                     $target.html('<div class="error_message">'+json.error_message+'</div>');
                  }
                  else {
                     alert(json.error_message);
                  }
               }
               else
                  alert("An unknown error occured");
         }
      }
   </script>
{/block}